﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using TTSIDAL;
using TTSModel;

namespace TTSDAL
{
    public class AssembleItem : BaseRepository<AssembleItemInfo>, IAssembleItem
    {
        #region 静态变量定义
        private const string PARM_ASSEMBLEITEM_ID = "@ID";
        private const string PARM_ASSEMBLEITEM_SUBSN = "@SubSN";

        #endregion

        #region 数据检索部分
        public IList<AssembleItemInfo> LoadEntities()
        {
            return null;
        }

        public AssembleItemInfo LoadEntity<T1>(T1 sn)
        {
            SqlParameter parm = GetParameter();
            parm.Value = sn;
            return ExcuteSqlToGetEntity("AssemblyItem_selectbySubSN", parm);
        }
        public IList<AssembleItemInfo> AssembleItem_GetbySubSN(string SubSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = SubSN;
            return ExcuteSqlToGetEntities("AssemblyItem_selectbySubSN", parm);
        }
        public IList<AssembleItemInfo> AssembleItem_GetbyID(int id)
        {
            SqlParameter parm = new SqlParameter(PARM_ASSEMBLEITEM_ID, SqlDbType.Int, 4);
            parm.Value = id;
            return ExcuteSqlToGetEntities("AssemblyItem_selectbyID", parm);
        }
        #endregion

        #region 重写基类方法
        public override AssembleItemInfo GetEntityRecord(SqlDataReader rdr)
        {
            AssembleItemInfo entity = new AssembleItemInfo()
            {
                ID = rdr.GetInt32(0),
                SN = rdr.GetValue(1).ToString(),
                SubSN = rdr.GetValue(2).ToString(),
                Tcode = rdr.GetValue(3).ToString(),
                Remark = rdr.GetValue(4).ToString(),
                IsLeaf = rdr.GetBoolean(5)
            };
            return entity;
        }

        public override AssembleItemInfo GetEntityRecord()
        {
            AssembleItemInfo entity = new AssembleItemInfo();
            return entity;
        }

        public override string GetInsertsp()
        {
            return "Unit_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_ASSEMBLEITEM_SUBSN, SqlDbType.NVarChar, 50);
            return parm;
        }
        #endregion
    }
}
